/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ihmproject.voletEdition;

import java.io.IOException;
import java.util.Vector;
import org.netbeans.api.visual.graph.GraphScene;
import org.netbeans.api.visual.widget.ConnectionWidget;
import org.netbeans.api.visual.widget.LabelWidget;
import org.netbeans.api.visual.widget.Widget;
import org.netbeans.api.visual.widget.general.IconNodeWidget;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.NotifyDescriptor.Confirmation;
import org.openide.cookies.SaveCookie;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.CookieSet;
import org.openide.util.ImageUtilities;
import org.openide.util.Utilities;

/**
 *
 * @author sebastien
 */
public class MyIconNodeWidget extends IconNodeWidget{

    private Vector deco;
    private String taskName;
    private String id;
    private String type;
    private Vector plateforme;
    private String precondition;
    private Vector<MyIconNodeWidget> children;
    private MyIconNodeWidget parent;
    private String operateur;
    private String IDEgdeOp;
    public MyNode node;

    

    //We will call this method, i.e., dummyNode.fire(),
    //from a document listener set on the text field:
    


    public MyIconNodeWidget(GraphScene<String,String> scene) {
        super(scene);
        children = new Vector<MyIconNodeWidget>();
        
        node = new MyNode();
    }

    public void addChild(MyIconNodeWidget child) {
        children.add(child);
    }

    public void majOP() {
        ConnectionWidget cw = (ConnectionWidget) ((GraphScene<String,String>)getScene()).findWidget(IDEgdeOp);
        LabelWidget lw = (LabelWidget) cw.getChildren().get(0);
        lw.setLabel(operateur);
        if (!operateur.equals("Aucun"))
            cw.setVisible(true);
        else
            cw.setVisible(false);
        getScene().validate();
    }

    public void setParent(MyIconNodeWidget parent) {
        this.parent = parent;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
        this.setLabel(taskName + " " + deco);
        getScene().validate();
    }

    public Vector<MyIconNodeWidget> getChilds (){
        return children;
    }

    public String getID() {
        return id;
    }

    public void setID(String ID) {
        this.id = ID;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setDecoration(Vector deco) {
        if (deco != null) {
            this.deco = deco;
            this.setLabel(taskName + " " + deco);
            getScene().validate();
        } else {
            this.deco = new Vector();
        }
    }

    public Vector getDecoration() {
        return this.deco;
    }

    public void setType(String type) {
        this.type = type;
        this.setImage(ImageUtilities.loadImage("org/ihmproject/treewindow/" + type + ".png"));
        getScene().validate();
    }

    public boolean isOperatorAddable(MyIconNodeWidget child) {
        return (this.children.indexOf(child) + 1) < children.size();
    }

    public MyIconNodeWidget nextChild(MyIconNodeWidget child) {
        if (isOperatorAddable(child)) {
            return children.get(this.children.indexOf(child) + 1);
        } else {
            return null;
        }
    }

    public String getType() {
        return type;
    }

    public void setPlateforme(Vector plateforme) {
        if (plateforme != null) {
            this.plateforme = plateforme;
            Widget lw0 = this.getChildren().get(2);
            if (plateforme.contains("PC")) {
                lw0.getChildren().get(0).setVisible(true);
            } else {
                lw0.getChildren().get(0).setVisible(false);
            }
            if (plateforme.contains("PDA")) {
                lw0.getChildren().get(1).setVisible(true);
            } else {
                lw0.getChildren().get(1).setVisible(false);
            }
            if (plateforme.contains("Mobile")) {
                lw0.getChildren().get(2).setVisible(true);
            } else {
                lw0.getChildren().get(2).setVisible(false);
            }
            if (plateforme.contains("Vocale")) {
                lw0.getChildren().get(3).setVisible(true);
            } else {
                lw0.getChildren().get(3).setVisible(false);
            }
            getScene().validate();
        } else {
            this.plateforme = new Vector();
        }
    }

    public void setOperateur(String operateur) {
        this.operateur = operateur;
        if (IDEgdeOp != null) {
            majOP();
        }
    }

    public String getOperateur () {
        return operateur;
    }

    public Vector getPlateforme() {
        return plateforme;
    }

    public void setPreCondition(String precondition) {
        this.precondition = precondition;
    }

    public String getPreCondition() {
        return precondition;
    }

    /**
     * @return the IDEgdeOp
     */
    public String getIDEgdeOp() {
        return IDEgdeOp;
    }

    /**
     * @param IDEgdeOp the IDEgdeOp to set
     */
    public void setIDEgdeOp(String IDEgdeOp) {
        this.IDEgdeOp = IDEgdeOp;
    }

     

}